<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;

/**
 * 会员接口
 */
class User extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    /**
    * 登录
    */
    public function login(){
        $account  = $this->request->request("account");
        $password = $this->request->request("password");
        $jgno = $this->request->request("jgno");
        if (!$account || !$password || !$jgno) {
            $this->error(__('Invalid parameters'));
        }

        $user = Db::name('basedata')->where(['Content9'=>$account,'Content10'=>$password,'Datatype'=>'作业队'])->field('id,Bh,Content1,Content2')->find();
        if(!$user) {
            $this->error('查询用户失败，请检查用户名和密码');
        }


        $info = Db::name('basedata')->where(['Partntid'=>$user['Bh'],'Datatype'=>'终端设备','Content1'=>'监控终端'])->field('Content2')->find();
        if(!$info) {
           $this->error('未获取到终端编号，登录失败');
        }


        
        $user['zdno'] =  $info['Content2'];

        //更新极光推送id到数据库
        Db::name('basedata')->where('id',$user['id'])->update(['Content8'=>$jgno]);

        $this->success('登录成功', $user);
    }
   
}
